***create counts over time for more than 50k
use "$data/demog_meta.dta", clear

drop if as_of<2010
egen p999=pctile(rate_spread), p(99.9)
keep if rate_spread<p999

keep if loan_amount>=50

by as_of, sort: egen five_less=count(rate_spread) if rate_spread>=5&rate_spread<5.75
by as_of, sort: egen six_less=count(rate_spread) if rate_spread>5.75&rate_spread<=6.5
by as_of, sort: egen six_more=count(rate_spread) if rate_spread>6.5

collapse (mean) five_less six_less six_more, by(as_of_year)
drop if as_of==.
twoway conn five_less as_of_year if as_of>=2010||conn six_less as_of_year if as_of>=2010, msymbol(S)||conn six_more as_of_year, msymbol(T)/*
*/ xline(2013.5)  legend(label(1 "5 to 5.75") label(2 "5.75 to 6.5") label(3 "6.5 to infinity"))/*
*/ ytitle(Number of Mortgages) yscale(range(0 1000)) graphregion(color(white)) bgcolor(white) xtitle(Year)

graph export "$figures/figure3_panela.eps", as(eps) preview(on) replace


***create counts over time for less than 50k
use "$figures/demog_meta.dta", clear

drop if as_of<2010
egen p999=pctile(rate_spread), p(99.9)
keep if rate_spread<p999

keep if loan_amount<50
by as_of, sort: egen seven_less=count(rate_spread) if rate_spread>=7&rate_spread<7.75
by as_of, sort: egen eight_less=count(rate_spread) if rate_spread>7.75&rate_spread<=8.5
by as_of, sort: egen eight_more=count(rate_spread) if rate_spread>8.5

collapse (mean) seven_less eight_less eight_more, by(as_of_year)
drop if as_of==.
twoway conn seven_less as_of_year if as_of>=2010||conn eight_less as_of_year if as_of>=2010, msymbol(S)||conn eight_more as_of_year, msymbol(T)/*
*/  xline(2013.5)  legend(label(1 "7 to 7.75") label(2 "7.75 to 8.5") label(3 "8.5 to infinity"))/*
*/ ytitle(Number of Mortgages) xtitle(Year) graphregion(color(white)) bgcolor(white)
graph export "$figures/figure3_panelb.eps", as(eps) preview(on) replace


